var _debug = false;
var _navig = function () {
    var Sys = {};
    var ua = navigator.userAgent.toLowerCase();
    var s;
    (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
        (s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
            (s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
                (s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
                    (s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;
    return Sys;
}();

var isleftMouseDown = function (e) {
    if(_navig.ie && e.button == 1){
        return true;
    }

    return e.button == 0;
}

if (!("console" in window)) {
    window.console = {
        log: function () {
        },
        error: function () {
        },
        warn: function () {
        }
    }
}
if (!("trim" in String.prototype)) {
    String.prototype.trim = function () {
        return this.replace(/^\s*/, "").replace(/\s*$/, "");
    }
}
if (!("remove" in Array.prototype)) {
    Array.prototype.remove = function (val) {
        var index = this.indexOf(val);
        if (index > -1) {
            this.splice(index, 1);
        }
    };
}

if (!("removeAll" in Array.prototype)) {
    Array.prototype.removeAll = function (val) {
        this.length = 0;
    };
}

if (!("map" in Array.prototype)) {
    Array.prototype.map = function (iter) {
        for(var i = 0;i<this.length;i++){
            console.log(this[i]);
            iter(this[i]);
        }
    };
}
if (!("indexOf" in Array.prototype)) {
    Array.prototype.indexOf = function (elt /*, from*/) {
        var len = this.length >>> 0;
        var from = Number(arguments[1]) || 0;
        from = (from < 0)
            ? Math.ceil(from)
            : Math.floor(from);
        if (from < 0)
            from += len;
        for (; from < len; from++) {
            if (from in this &&
                this[from] === elt)
                return from;
        }
        return -1;
    };
}

//ie8 splice(int) bug
// check if it is IE and it's version is 8 or older
if (document.documentMode && document.documentMode < 9) {
    // save original function of splice
    var originalSplice = Array.prototype.splice;

    // provide a new implementation
    Array.prototype.splice = function() {
        var arr = [],  i = 0,  max = arguments.length;

        for (; i < max; i++){
            arr.push(arguments[i]);
        }

        // if this function had only one argument
        // compute 'deleteCount' and push it into arr
        if (arr.length==1) {
            arr.push(this.length - arr[0]);
        }

        // invoke original splice() with our new arguments array
        return originalSplice.apply(this, arr);
    };
}